package charts ;

import charts.series.dots.Scat;
import charts.series.Element;
import charts.series.dots.DotFactory;
import string.Utils;
import flash.geom.Point;
import flash.display.Sprite;
import charts.series.dots.DefaultDotProperties;
import ColorConverter.Color;

typedef SCATTERBASESTRUCT = {
	var values		: Array<Dynamic>;
	var dot_size		: Int;
	var halo_size		: Int;
	var width		: Int;
	var color		: Color;
	var tip			: String;
};

typedef SCATTERSTRUCT = {> SCATTERBASESTRUCT,
	var axis		: String;
	var text		: String;
	var font_size		: Int;
	//var values		: Array<Dynamic>;
};

typedef SCATTERLINESTRUCT = {> SCATTERSTRUCT,
	var stepgraph		: String;
};

class ScatterBase extends Base {

	// TODO: move this Into Base
	var style: SCATTERLINESTRUCT;
	var default_style:DefaultDotProperties;
	
	public function new () {super();}
	
	//
	// called from the base object
	//
	override function get_element( index: Int, value: Dynamic ): Element {
		// we ignore the X value (index) passed to us,
		// the user has provided their own x value
		
		var default_style: SCATTERLINESTRUCT = {
			dot_size:		this.style.dot_size,
			halo_size:		this.style.halo_size,
			width:			this.style.width,	// stroke
			color:			this.style.color,
			tip:			this.style.tip
		};
		
		// Apply dot style defined at the plot level
		ObjectHelper.merge_2( this.style.dot_style, default_style );
		// Apply attributes defined at the value level
		ObjectHelper.merge_2( value, default_style );
			
		// our parent color is a number, but
		// we may have our own color:
		//if(Std.is(default_style.color,String ))
		//	default_style.color = Utils.get_color( default_style.color );
		
		var prop:Properties = new Properties( value, this.default_style);
			
		return DotFactory.make( index, prop );
		
		// return DotFactory.make( 0, new Properties( { } ));// default_style );
	}
	
	// Draw points...
	public override function resize ( sc:ScreenCoordsBase ): Void {
		
		var tmp:Sprite;
		for ( i in 0...this.numChildren ) {
			tmp = cast(this.getChildAt(i),Sprite);
			
			//
			// filter out the line masks
			//
			if(Std.is(tmp,Element))
			{
				var e:Element = cast(tmp,Element);
				e.resize( sc );
			}
		}
	}

}
